package com.jthinker.service.impl;

import com.jthinker.bean.vo.QueryResult;
import com.jthinker.bean.vo.SearchFilter;
import com.jthinker.dao.MenuDao;
import com.jthinker.service.CommonService;
import com.jthinker.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * User: Gang Chen
 * Date: 2015/3/15 21:32
 */
@Service
public class MenuServiceImpl implements MenuService
{
    private static final Logger LOGGER = LoggerFactory.getLogger(MenuService.class);

    @Resource
    private MenuDao menuDao;

    @Resource
    private CommonService commonService;

    @Override
    public void create(Map<String, Object> record) throws Exception
    {
        try
        {
            menuDao.create(record);
        }
        catch (Exception e)
        {
            LOGGER.error("Exception: {}", e);
        }

    }

    @Override
    public List<Map<String, Object>> findAll()
    {
        return menuDao.findAll();
    }

    @Override
    public QueryResult<Map<String, Object>> query(SearchFilter filter)
    {
        return commonService.queryTable(filter, "sys_menu");
    }

    @Override
    public void delete(Serializable id) throws Exception
    {
        menuDao.delete(id);
    }
}
